<?php
include("include/haut.php");

if(!isConnected() && estAdmin(getInfos($_SESSION['id']))){
	header("Location: index.php");
	exit();
}
if(isset($_POST['titre']) && isset($_POST['presentation'])){
	$titre = $_POST['titre'];
	$presentation = $_POST['presentation'];
	if(isset($_GET['action'])){
		if($_GET['action'] == "maj"){
			editNews($_GET['id'],$presentation, $titre);
	}
}
	else
		{
			addNews($titre, $presentation,$_SESSION['id']);
		}

}		if(isset($_GET['action'])){
		if($_GET['action'] == "remove"){
					suprNews($_GET['id']);
					header("Location: gestion_news.php");
					
				}
			}
$maj = false;
?>

<div id="corps">
	<h1>Edition News</h1>
	<div id="centre">
		<?php
		if(isset($_GET['action']) && isset($_GET['id'])){
			
			if($_GET['action'] == "maj"){
				$maj = true;
				?>
				<form action="?action=maj&id=<?php echo $_GET['id']; ?>" method="POST"><?php
			}
		}else
		{
			?>
			<form action="" method="POST">
			<?php
		}
		
			if($maj){
				$news = getNewsID($_GET['id']);
				?>
			<label for="titre">Titre:</label><br />
			<input type="text" name="titre" id="titre" size="50" value="<?php echo $news['titre']; ?>"/><br />
			<label for="presentation">Présentation:</label><br />
			<div id="tiny_mce">
			<textarea name="presentation" id="presentation"  rows="20" cols="70">
			<?php echo $news['news']; ?>
			</textarea><br />
		</div>
		<?php
			}
			else{
				?>
			<label for="titre">Titre:</label><br />
			<input type="text" name="titre" id="titre" size="50"/><br />
			<label for="presentation">Contenu:</label><br />
			<div id="tiny_mce">
			<textarea name="presentation" id="presentation"  rows="20" cols="70">
			
			</textarea><br />
		</div>
		<?php
		}?>
			<input type="submit" value="Enregistrer"/>
		</form>
	</div>
</div>

<?php
include("include/bas.php");
?>
